#! user/bin/python
# -*- coding: utf-8 -*-

"""
Created on 2021/6/30 9:46

@File: gui_mainloop_demo.py
@Author: LT
@Description: 因为mainloop()退出后，是无法继续从已销毁的窗口组件中重新获取用户输入的。为了解决这个问题，就得自行设置一个变量来保存用户输入的值。
"""
from tkinter import *
from tkinter.filedialog import *


class GuiDemo(Frame):
    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        self.pack()
        self.lbl = Label(self, text="请点击按钮选择名为template的excel模板")
        self.lbl.pack(side=TOP, expand=YES)
        self.btn = Button(self, text="Open target template excel", command=self.openfile, relief=RIDGE)
        self.btn.pack(side=TOP, fill=BOTH)

    def openfile(self):
        self.open_name = askopenfilename()                # 获取用户指定的名字为template.xlsx的excel模板


if __name__ == '__main__':
    myexceldialog = GuiDemo()
    myexceldialog.mainloop()

    fetched_excel_path = myexceldialog.open_name
    print(fetched_excel_path)
